<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/3/29
 * Time: 19:00
 */
function object2array($object)
{
    $array = [];
    if (is_object($object)) {
        foreach ($object as $key => $value) {
            $array[$key] = $value;
        }
    } else {
        $array = $object;
    }
    return $array;
}

function child($list, $pid = 0)
{
    $arr = [];
    foreach ($list as $li) {
        if ($li['pid'] == $pid) {
            $child = child($list, $li['id']);
            if (!empty($child)) {
                $li['children'] = $child;
            }
            unset($li['id']);
            unset($li['pid']);
            if(empty($li['path']) ) unset($li['path']);
            $arr[] = $li;
        }
    }
    return $arr;
}